import Vue from 'vue'

const permission = {
  inserted(el, binding, vnode, oldVnode) {
    const { value } = binding
    const hasPermission = Vue.prototype.hasPermission(value)
    if (hasPermission) return
    el.remove()
  },
}

const directives = {
  permission,
}

export default {
  install(Vue) {
    Object.entries(directives).forEach(([k, v]) => {
      Vue.directive(k, v)
    })
  },
}
